package com.example.demo8;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/CustomerServlet")
public class CustomerServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=gb2312");
        String name = request.getParameter("name") + " , hello!";
        String email = request.getParameter("email");
        String phone = request.getParameter("phone");
        CustomerBean customer = new CustomerBean(name, email, phone);
        HttpSession session = request.getSession();
        session.setAttribute("customer", customer);
        RequestDispatcher view = request.getRequestDispatcher("/displayCustomer.jsp");
        view.forward(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
